package com.best.oasis.settlement.web.exception;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.best.oasis.settlement.service.base.BusinessException;


/**
 * action 层异常
 * 这里可以添加字段错误信息和普通错误信息
 * @author BL00064
 *
 */
/**
 * @author BL00064
 *
 */
public class ActionException extends RuntimeException {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public ActionException() {
		super();
	}
	public ActionException(String arg0, Throwable arg1) {
		super(arg0, arg1);
	}
	public ActionException(String arg0) {
		super(arg0);
	}
	public ActionException(Throwable arg0) {
		super(arg0);
	}
	public ActionException(BusinessException be) {
		super(be);
		this.fieldErrors = be.getFieldErrors();
		this.errors = be.getErrors();
	}
	/**
	 * 字段错误信息列表
	 */
	private Map<String, String> fieldErrors;
	/**
	 * 错误信息列表
	 */
	private List<String> errors;
	
	/**
	 * 添加字段错误信息
	 * @param fieldName 字段名
	 * @param errorMsg 错误信息
	 */
	public void addFieldError(String fieldName, String errorMsg){
		if(fieldErrors == null){
			fieldErrors = new LinkedHashMap<String, String>();
		}
		fieldErrors.put(fieldName, errorMsg);
	}
	/**
	 * 删除字段错误信息
	 * @param fieldName 字段名
	 */
	public boolean removeFieldError(String fieldName, String errorMsg){
		if(fieldErrors == null){
			return false;
		}
		fieldErrors.remove(fieldName);
		return true;
	}
	
	/**
	 * 添加错误信息
	 * @param errorMsg 错误信息
	 */
	public void addError(String errorMsg){
		if(errors == null){
			errors = new ArrayList<String>();
		}
		errors.add(errorMsg);
	}
	/**
	 * 删除所有错误信息
	 */
	public boolean clearErrors(){
		if(errors == null){
			return false;
		}
		errors.clear();
		return true;
	}
	
	public Map<String, String> getFieldErrors() {
		return fieldErrors;
	}

	public void setFieldErrors(Map<String, String> fieldErrors) {
		this.fieldErrors = fieldErrors;
	}
	public List<String> getErrors() {
		return errors;
	}
	public void setErrors(List<String> errors) {
		this.errors = errors;
	}
	
}
